package com.xique.api.service.service.impl;

import com.xique.api.api.domain.ApiThirdToken;
import com.xique.api.mapper.ApiThirdTokenMapper;
import com.xique.api.service.service.IApiThirdTokenService;
import com.xique.common.core.text.Convert;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shd
 * @create 2022/2/24 13:58
 */
@Service
public class ApiThirdTokenServiceImpl implements IApiThirdTokenService {

    @Autowired
    private ApiThirdTokenMapper apiThirdTokenMapper;

    /**
     * 查询第三方登录token
     *
     * @param id 第三方登录tokenID
     * @return 第三方登录token
     */
    @Override
    public ApiThirdToken selectApiThirdTokenById(Long id) {
        return apiThirdTokenMapper.selectApiThirdTokenById(id);
    }

    /**
     * 查询第三方登录token列表
     *
     * @param apiThirdToken 第三方登录token
     * @return 第三方登录token
     */
    @Override
    public List<ApiThirdToken> selectApiThirdTokenList(ApiThirdToken apiThirdToken) {
        return apiThirdTokenMapper.selectApiThirdTokenList(apiThirdToken);
    }

    /**
     * 新增第三方登录token
     *
     * @param apiThirdToken 第三方登录token
     * @return 结果
     */
    @Override
    public int insertApiThirdToken(ApiThirdToken apiThirdToken) {
        apiThirdToken.setCreateTime(DateUtils.getNowDate());
        apiThirdToken.setCreateUser(SecurityUtils.getUserId());
        apiThirdToken.setUpdateTime(DateUtils.getNowDate());
        apiThirdToken.setUpdateUser(SecurityUtils.getUserId());
        return apiThirdTokenMapper.insertApiThirdToken(apiThirdToken);
    }

    /**
     * 修改第三方登录token
     *
     * @param apiThirdToken 第三方登录token
     * @return 结果
     */
    @Override
    public int updateApiThirdToken(ApiThirdToken apiThirdToken) {
        apiThirdToken.setUpdateTime(DateUtils.getNowDate());
        apiThirdToken.setUpdateUser(SecurityUtils.getUserId());
        return apiThirdTokenMapper.updateApiThirdToken(apiThirdToken);
    }

    /**
     * 删除第三方登录token对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteApiThirdTokenByIds(String ids) {
        return apiThirdTokenMapper.deleteApiThirdTokenByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除第三方登录token信息
     *
     * @param id 第三方登录tokenID
     * @return 结果
     */
    @Override
    public int deleteApiThirdTokenById(Long id) {
        return apiThirdTokenMapper.deleteApiThirdTokenById(id);
    }

}
